package tests;
import java.util.List;

import java.util.Properties;

import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import javax.naming.Context;

import negocio.Books;
import negocio.BooksRemote;
import negocio.MyBeanRemote;

import ejb.IAdministradorHandlerRemote;
import entidades.Book;


public class BookTest {
	
	@PersistenceContext (unitName="EJB Tutorial")
	private EntityManager em;
	
	
	public static void main(String[] args) {
		Book b = new Book("Mi primer Libro","Juan");
	
		try {
            Properties props = new Properties();
            
           	props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
            props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
            props.setProperty("java.naming.provider.url", "jnp://localhost:1099");         
            
            InitialContext ctx = new InitialContext(props);            
            IAdministradorHandlerRemote beanAHandler = (IAdministradorHandlerRemote) ctx.lookup("EARTutorial/AdministradorHandler/remote");
            
            
            long nroserie = 123789347;
            float precio = 155;
            beanAHandler.altaProducto(nroserie, precio, "pekelongo");
          //  BooksRemote booksBean = (BooksRemote) ctx.lookup("EARTutorial/Books/remote");
            
           /* bean.addBook(b);
            
            List<Book> libros = bean.getBooks();
            
            for (Book l:libros){
            	System.out.println("titulo: "+l.getTitle()+" autor "+ l.getAuthor());
            	
            }
            
            libros = bean.getBooksByFernando();
            
            for (Book l:libros){
            	System.out.println("titulo: "+l.getTitle()+" autor "+ l.getAuthor());
            	
            }*/
            
           
        } catch (Exception e) {
            e.printStackTrace();
        } 
		
	
	}
	
	
	
	
}
